************************************************************
*This file builds measures of robot exposure at state-level*
************************************************************

use "$clean_data_automation/states_exposure_robots.dta", clear

*Keep relevant dates*
rename *93_00_ *_y1990
rename *00_07_ *_y2000
rename *07_14_ *_y2007

*Create stacked differences*
keep czone *_y19* *_y20* statefip
order *_y19* *_y20*

*obtain list of variables to reshape*
quietly: describe *y1990, varlist
local varlist = r(varlist)
local finalvar: subinstr local varlist "_y1990" "_y", all
reshape long `finalvar' , i(czone statefip) j(year)
rename *_y *

replace year = 2008 if year == 2007

*Save*
save "$final_data_automation/states_ExposureAutomation.dta", replace

*Aggregated at state level

collapse (mean) expof_state_us_adj expof_state_euro7_qo, by(statefip year)

*Save*
save "$final_data_automation/states_ExposureAutomationAggregated.dta", replace
